package base.thio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class GetChannel {
	
	private static final int BSIZE=1024;
	
	public static void main(String[] args) throws Exception{
		String path="d:a.txt";
		FileChannel channel=new FileOutputStream(path).getChannel();
		channel.write(ByteBuffer.wrap("some txt and who the hells are you. ".getBytes()));
		channel.close();
		
		channel=new RandomAccessFile(path, "rw").getChannel();
		channel.position(channel.size());
		channel.write(ByteBuffer.wrap("yeath you are ".getBytes()));
		channel.close();
		
		channel=new FileInputStream(path).getChannel();
		ByteBuffer buffer=ByteBuffer.allocate(BSIZE);
		channel.read(buffer);
		buffer.flip();
		while(buffer.hasRemaining()){
			System.out.print((char)buffer.get());
		}
		
	}
}
